<?php
class page_register Extends page_Base {

    var $access_max = 0;

    public function index() {
        $z = $this->tp->apply_sys('form_register');
        $this->tp->g_add('content',$z);
    }

    public function getSettings(){
        
    }

    public function new_reg() {

        $error = '';
        $user = $this->registry->get('user');

        $login = trim($_POST['login']);
        $pass = trim($_POST['pass']);
        $mail = trim($_POST['mail']);
        $code = trim($_POST['code']);

        if(preg_match('/^[a-zA-Z0-9]+$/',$login) == 0 ) {
            $error .= 'Invalid User Name ! <br /><br />';
        }

        if(preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])' .
'(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i',$mail) == 0 ) {
            $error .= 'Invalid e-mail ! <br /><br />';
        }

        if(preg_match('/^[a-zA-Z0-9]+$/',$pass) == 0 ) {
            $error .= 'Invalid Password ! <br /><br />';
        }

        if(!empty($error)) {
            $this->tp->g_add('content', $error);
            $this->index();
            return;
        }

        $error = $user->doRegister($login, $mail, $pass);

        if(!empty($error)) {
            $this->tp->g_add('content', $error);
            $this->index();
            return;
        }
        $this->tp->g_add('content',' Email with activation link was sent !');


    }

    public function confirm() {
        $user = $this->registry->get('user');
        if($user->activateReg($this->args[0])) {
            header("Location: {$config['misc']['site_url']}?p=user/home");
        }
        else {
            $this->tp->g_add('content',' Account not activated !');
        }
    }

}
?>
